home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 46
/
Amiga Format CD46 (1999-10-20)(Future Publishing)(GB)[!][issue 1999-12].iso
/
-in_the_mag-
/
reader_requests
/
scilab
/
demos
/
control
/
lqg.dem
< prev
next >
Wrap
Text File
|
1999-09-16
|
3KB
|
102 lines
exec(SCI+'/demos/control/scheme.dem');
s=poly(0,'s');z=poly(0,'z');
x_message(['Simple example of SISO LQG Design';
'Demo is in file '+SCI+'/demos/control/lqg.dem';
'Computes the LQG compensator and plots response'])
n=x_choose(['Continuous time';'Discrete time'],'Select time domain');
select n
case 0
return
case 1
s=poly(0,'s');
str='(s-1)/(s^2-5*s+1)';
rep=x_dialog('Nominal plant?',str)
if rep==[] then return,end
Plant=evstr(rep);
Plant=syslin('c',Plant);
case 2
z=poly(0,'z');
str='(z+1)/(z^2-5*z+2)'
rep=x_dialog('Nominal plant?',str)
if rep==[] then return,end
Plant=evstr(rep);
Plant=syslin('d',Plant);
end
//Nominal Plant
P22=tf2ss(Plant); //...in state-space form
[ny,nu,nx]=size(P22);
x_message('Now enter weighting matrices');
rep=x_matrix('x-weighting matrix',eye(nx,nx))
if rep==[] then return,end
Qx=evstr(rep);
rep=x_matrix('u-weighting matrix',eye(nu,nu));
if rep==[] then return,end
Qu=evstr(rep);
bigQ=sysdiag(Qx,Qu);
rep=x_matrix('x-noise covariance matrix',eye(nx,nx))
if rep==[] then return,end
Rx=evstr(rep);
rep=x_matrix('y-noise covariance matrix',eye(ny,ny))
if rep==[] then return,end
Ry=evstr(rep);
bigR=sysdiag(Rx,Ry);
[Plqg,r]=lqg2stan(P22,bigQ,bigR); //LQG pb as a standard problem
Klqg=lqg(Plqg,r); //LQG compensator
disp(spec(h_cl(Plqg,r,Klqg)),'closed loop eigenvalues:'); //Check internal stability
[Slqg,Rlqg,Tlqg]=sensi(P22,Klqg); //Sensitivity functions
disp(clean(ss2tf(Slqg)),'Sensitivity function');
disp(clean(ss2tf(Tlqg)),'Complementary sensitivity function');
x_message('Closed-loop response');
resp=['Frequency response';'Time response'];
while %t do
n=x_choose(resp,'Select response(s)');
select n
case 0
disp("LQG demo stops!");break;
case 1
xbasc(0);xset("window",0);xselect();bode(Tlqg);
case 2
if Plant(4)='c' then
defv=['0.1','20'];
title='Enter Sampling period and Tmax';
rep=x_mdialog(title,['Sampling period?';'Tmax?'],defv)
if rep==[] then break,end
dttmax=evstr(rep)
dt=evstr(dttmax(1));tmax=evstr(dttmax(2));
t=0:dt/5:tmax;
n1=x_choose(['Step response?';'Impulse response?'],'Simulation:');
select n1
case 1 then
xbasc(1);xset("window",1);xselect();
plot2d([t',t'],[(csim('step',t,Tlqg))',ones(t')])
case 2 then
xbasc(1);xset("window",1);xselect();
plot2d([t',t'],[(csim('impul',t,Tlqg))',0*t'])
end
end
if Plant(4)='d' then
defv=['30'];
title='Tmax?';
rep=x_mdialog(title,['Tmax='],defv)
if rep==[] then break,end
Tmax=evstr(rep);
n2=x_choose(['Step response?';'Impulse response?'],'Simulation:');
select n2
case 0 then
break;
case 1 then
u=ones(1,Tmax);u(1)=0;
xbasc(1);xset("window",1);xselect();
plot2d([(1:Tmax)',(1:Tmax)'],[(dsimul(Tlqg,u))',(ones(1:Tmax)')])
case 2 then
u=zeros(1,Tmax);u(1)=1;
xbasc(1);xset("window",1);xselect();
plot2d((1:Tmax)',(dsimul(Tlqg,u))')
end
end
end
end